const ctx = wx.createCanvasContext('myCanvas');

Page({
  data:{
    mosaic:true,
    path:"",
  },
  open(){
    wx.chooseImage({
      count:1,
    }).then(res=>{
      console.log(res);
      ctx.drawImage(res.tempFilePaths[0],0,0,240,380);
      ctx.draw();
      console.log(res);
    });
  },
  move(e){
    if(this.data.mosaic){
      ctx.setFillStyle('#666')
      ctx.arc(e.touches[0].x,e.touches[0].y, 20, 0, 2 * Math.PI)
      ctx.fill(true);
      ctx.draw(true);
      ctx.setFillStyle('#888')
      ctx.arc(e.touches[0].x,e.touches[0].y, 10, 0, 2 * Math.PI)
      ctx.fill(true);
      ctx.draw(true);
    }else{
      ctx.clearRect(e.touches[0].x,e.touches[0].y,20,20);
      ctx.draw(true);
    }
  },
  clear(){
    this.setData({
      mosaic:false
    });
  },
  mosaic(){
    this.setData({
      mosaic:true,
    })
  },
  save(){
    wx.canvasToTempFilePath({
      canvasId: 'myCanvas',
    }).then(res=>{
      this.setData({
        path:res.tempFilePath,
      });
      console.log(res);
    })
  },
  seal(res){
    ctx.setFillStyle('red');
    ctx.setFontSize(48);
    ctx.fillText("21121106黄锦涛",0,200);
    ctx.draw(true);
  },
  onShareAppMessage(){
    return {
      title:"黄锦涛图片",
      desc:"有趣的马赛克",
      path:"/pages/work11/work11"
    }
  }
})